/**
 * <p>radio代码选择控件，数据来自系统代码字典表，在代码字典变动的时候“内存同步”后会更新codedata.js</p>
 * xtype = cceafradiogroupfield

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.RadioGroupField
 * @extends Ext.form.RadioGroup
 * @since 1.0
 */
Ext.define('cceaf.control.RadioGroupField',{
	extend: 'Ext.form.RadioGroup', 
	requires: [
   	    'cceaf.ControlDefaultConfig'
    ],
    alias: 'widget.cceafradiogroupfield',
       	
	constructor: function(config){
		config = config || {};

		var radioName = config.radioName;
		if(!radioName){
			cceaf.util.ExtHelper.showInfoDialog('radiogroup必须设置radioName属性（此值将提交）！');
			return;
		}
		
		var inputValue;
		if(config.inputValue){
			inputValue = config.inputValue;
		}
		else{
			inputValue = '';
		}
		
		var queryMode;
		if(config.queryMode){
			queryMode = config.queryMode;
		}
		else{
			queryMode = 'local';
		}
		
		var store = config.store;
		if (queryMode == 'local') {
			var data = eval('_jsonCode.' + config.codeType);
			if (data == null) {
				data = [];
			}
			
			store = new Ext.data.Store({
		    	model: 'cceaf.model.main.CceafCode',
		    	//autoLoad: true,
		    	data: data
		    });
		} else {
			store = new Ext.data.Store({
		    	model: 'cceaf.model.main.CceafCode',
		    	//autoLoad: true,
		    	proxy: {
		    		type: 'ajax',
		    		url: 'getCodeListOfPageDataProvider.action',
		    		extraParams: {codetype: config.codeType}
				}
		    });
		}
		//alert(config.inputValue);
		
		var items = [];
		var i = 0;
		store.each(function(record){
			var checked = false;
			if (record.get("value") == inputValue) {
				checked = true;
			}
			items[i] = {
				boxLabel: record.get("name"), 
				xtype: 'radiofield',
				name: radioName,
				inputValue: record.get("value"),
				checked: checked
			};
			i++;
		});

		var defaultFieldWidth = cceaf.ControlDefaultConfig.DEFAULT_FIELD_WIDTH;
		config = Ext.applyIf(config, {
			inputValue: inputValue,
			//name: "radiogroup_" + config.name,
			width: defaultFieldWidth,
		    items: items,
		    listeners: {
		    	change: function(rg,newValue,oldValue){
		    		//var radioGroupName = rg.getName();
		    		//var name = radioGroupName.substr(11);
		    		rg.inputValue = newValue[radioName];
		    	}
	        }
		});

		cceaf.control.RadioGroupField.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * 包含radio的名字
	 * 
	 * @property radioName 
     * @type String
     * @default null
	 */
	radioName: null,
	
	/**
	 * 代码类型，必须填写
	 *
     * @property codeType 
     * @type String
     * @default null
     */
	codeType: null,
	
	/**
	 * 代码值
	 *
     * @property inputValue 
     * @type String
     * @default ''
     */
	inputValue: '',
	
	/**
	 * 查询方式
	 *
     * @property queryMode 
     * @type String
     * @default 'local'
     */
	queryMode: 'local',
	
	/**
	 * 得到当前选中radio的值
	 * 
	 * getValue是得到以radio name作为key的数组
	 */
	getInputValue: function(){
		return this.inputValue;
	}
});